background in JAVA [closed]

Posted by leen.zd on Programmers See other posts from Programmers or by leen.zd
Published on 2012-03-23T15:43:02Z Indexed on 2012/03/23 17:39 UTC
Read the original article Hit count: 205

Filed under:

how can i put a background image in my java code? this is my code... what's error?

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class background extends JFrame {
    private Container c;
    private JPanel imagePanel;

    public background() {
        initialize();
    }

    private void initialize() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        c = getContentPane();
        imagePanel = new JPanel() {
            public void paint(Graphics g) {
                try {
                    BufferedImage image = ImageIO.read(new File("http://www.signe-zodiaque.com/images/signes/balance.jpg"));
                    g.drawImage(image, 1000, 2000, null);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        };
        imagePanel.setPreferredSize(new Dimension(640, 480));
        c.add(imagePanel);
    }

© Programmers or respective owner